﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using V5_Model;

namespace V5_EShop
{
    public partial class SaveItem : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var ID = Request.Form["ID"] + string.Empty;
            var Amount = Request.Form["Amount"] + string.Empty;

            int Am = 1;

            if (ID != "")
            {
                if (!int.TryParse(Amount, out Am))
                    Am = 1; 
                var ItemList = (List<BuyerItem>)Session["BuyerItemList"];

                if (ItemList == null)
                    ItemList = new List<BuyerItem>();
                //else
                //{
                //    var tItem = ItemList.Where(t => t.ID == ID).FirstOrDefault();

                //    if (tItem != null)
                //    {
                //        Response.Write("不能重复添加同一样产品！");
                //        Response.End();
                //    }


                //}
                ItemList.Add(new BuyerItem() { 
                    gid = Guid.NewGuid(),
                    ID = ID,
                    Amount = Am 
                });


                Session["BuyerItemList"] = ItemList;


                Response.Write("添加成功");
                Response.End();
                
            }
            Response.Write("非法操作！");
            Response.End();
        }
    }
}